#ifndef BINDGRAPHOPERATION_H_
#define BINDGRAPHOPERATION_H_

#include "graph_support/alg_correctness_tests/generate_graph/IGraphOperation.h"


namespace generate_graph
{

template< typename GenFn, typename DataT = int >
class BindGraphOperation : public IGraphOperation
{
public:
	BindGraphOperation(
			const GenFn & genFn,
			DataT data = 0,
			int arity = 1
	)
		: genFn( genFn )
		, data( data )
		, arity( arity )
	{
	}

	virtual GraphPtr applyOperation( GraphPtr gptr )
	{
		for ( int i = 0; i < arity; i++ )
		{
			gptr = genFn( gptr, data );
		}
		return gptr;
	}

private:
	GenFn genFn;
	DataT data;
	int arity;
};

template< typename GenFn, typename DataT >
// TODO: remove data from here
IGraphOperationPtr MKBindGraphOperation(
		GenFn genFn,
		DataT data,
		int arity = 1
) {
	return IGraphOperationPtr(
			new BindGraphOperation< GenFn, DataT >(
					genFn, data, arity ) );
}

}

#endif /* BINDGRAPHOPERATION_H_ */
